package com.aaa.service.sas.impl;

import com.aaa.dao.sas.TSasRecordMapper;
import com.aaa.entity.MyPage;
import com.aaa.entity.sas.TSasRecord;
import com.aaa.entity.sas.TjMessage;
import com.aaa.entity.sas.Ttongji;
import com.aaa.service.sas.TSasRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class TSasRecordServiceImpl implements TSasRecordService {
    @Autowired
    private TSasRecordMapper tSasRecordMapper;
    @Override
    public TSasRecord checkrecord(TSasRecord record) {
        TSasRecord tSasRecord=tSasRecordMapper.selectOne(record);
        return tSasRecord;
    }

    @Override
    public int insertRecord(TSasRecord record) {
        record.setCreatetime(new Date());
        int i=tSasRecordMapper.insert(record);
        System.out.println(record.getId());
        return record.getId();
    }

    @Override
    public List<Map<String,Object>> getTjData() {
        return tSasRecordMapper.getTjData();
    }

    @Override
    public PageInfo getTjData2(MyPage myPage, TjMessage tjMessage) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        return new PageInfo(tSasRecordMapper.getTjData2(tjMessage));
    }

    @Override
    public PageInfo getAll(MyPage myPage, TSasRecord sasRecord) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        Example example=new Example(TSasRecord.class);
        if (sasRecord.getUsername()!=null){
            example.createCriteria().andLike("username",sasRecord.getUsername());

        }
        example.setOrderByClause("createtime desc");
        List<TSasRecord> select=tSasRecordMapper.selectByExample(example);
        PageInfo pageInfo=new PageInfo(select);

        return pageInfo;
    }

    @Override
    public PageInfo getDetailMsg(MyPage myPage, Integer id) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<Map<String,Object>> details=tSasRecordMapper.getDatails(id);
        PageInfo pageInfo =new PageInfo(details);
        return pageInfo;
    }
}
